<%@ page import="com.webtest.mvctest2.model.Customer" %><%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/7/28
  Time: 23:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>update</title>
</head>
<body>
<br>
<span style="color: red; ">
    <%=request.getAttribute("message") == null ? "" : request.getAttribute("message")%>
</span>
<br><br>
<%
    String id = null;
    String oldName = null;
    String name = null;
    String address = null;
    String phone = null;

    Customer customer = (Customer) request.getAttribute("customer");
    if (customer != null) {
        id = String.valueOf(customer.getId());
        oldName = customer.getName();
        name = customer.getName();
        address = customer.getAddress();
        phone = customer.getPhone();
    } else {
        id = request.getParameter("id");
        oldName = request.getParameter("oldName");
        name = request.getParameter("oldName");
        address = request.getParameter("address");
        phone = request.getParameter("phone");
    }

%>
<form action="updateCustomer.do" method="post">
    <%--使用隐藏域来保存要修改的Customer对象的id--%>
    <input type="hidden" name="id" value=<%=id%>>
    <input type="hidden" name="oldName" value=<%=oldName%>>
    <table>
        <tr>
            <td>Customer Name</td>

            <td><input type="text" name="name"
                       value="<%=name==null?"":name%>"/></td>
        </tr>
        <tr>
            <td>Address</td>
            <td><input type="text" name="address"
                       value="<%=address==null?"":address%>"/></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone"
                       value="<%=phone==null?"":phone%>"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="submit"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
